<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            'name'         => 'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,' . Auth::id(),
            'email'        => 'required|email',
            'introduction' => 'max:80',
            'avatar'       => 'mimetypes:image/png,image/jpg,image/gif,image/jpeg|dimensions:min_width=208,min_height=208'
        ];
    }

    public function messages()
    {
        return [
            'avatar.mimetypes'  => '头像必须是 png，jpg，gif，jpeg 格式的图片',
            'avatar.dimensions' => '图片的清晰度不够，宽和高需要208px以上',
            'name.unique'       => '用户名已被占用，请重新填写',
            'name.regex'        => '用户名只支持英文、数字，横线和下划线',
            'name.between'      => '用户必须介于 3 - 25 个字符之间',
            'name.required'     => '用户名不能为空'
        ];
    }
}
